package router

import (
	"gf/app/api/admin"
	"gf/app/api/home"
	"gf/app/service"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

func init() {
	s := g.Server()
	s.Group("/api.v1", func(group *ghttp.RouterGroup) {

		//允许跨域
		group.Middleware(service.Middleware.CORS, service.Middleware.Ctx)

		group.Group("/admin", func(group *ghttp.RouterGroup) {
			//登录
			group.POST("/login", admin.User.Login)

			//授权中间件
			group.Middleware(service.Middleware.Auth)

			//重置密码
			group.PUT("/resetPassword", admin.User.ResetPassword)

			//上传
			group.POST("/upload", admin.File.Upload)

			//文章
			group.Group("/article", func(group *ghttp.RouterGroup) {

				//列表
				group.GET("/", admin.Article.List)

				//详情
				group.GET("/:id", admin.Article.Info)

				//添加
				group.POST("/", admin.Article.Add)

				//修改
				group.PUT("/:id", admin.Article.Edit)

				//删除
				group.DELETE("/:id", admin.Article.Del)
			})

			//文章分类
			group.Group("/articleCategory", func(group *ghttp.RouterGroup) {
				group.GET("/", admin.ArticleCategory.List)

				group.POST("/", admin.ArticleCategory.Add)

				group.PUT("/:id", admin.ArticleCategory.Edit)

				group.DELETE("/:id", admin.ArticleCategory.Del)
			})

		})

		//前台
		group.GET("/list", home.Article.List)

		group.GET("/article/:id",home.Article.Info)

		group.GET("/articleCategory",home.ArticleCategory.List)
	})

}
